﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Data.SqlClient;
using QA_System.QASysDataSetTableAdapters;

namespace QA_System
{
    public class Owner
    {
        private static OWNERTableAdapter ownerAdapter = new OWNERTableAdapter();

        public static QASysDataSet.OWNERDataTable GetAllOwner()
        {
            QASysDataSet.OWNERDataTable ownerTable = ownerAdapter.GetData();
            return ownerTable;
        }

        public static Ownerfield GetByOwnerId(int ownerId)
        { 
            QASysDataSet.OWNERDataTable ownerTable = ownerAdapter.GetDataByOwnerId(ownerId);
            if (ownerTable.Rows.Count == 0)
                return null;
            else
            {
                Ownerfield FData = new Ownerfield();                
                FData.Own_ID = int.Parse(ownerTable.Rows[0]["Own_Id"].ToString());
                FData.Own_Name = ownerTable.Rows[0]["Name"].ToString();
                if (ownerTable.Rows[0]["Birth"].ToString() != "")
                    FData.Own_Birth = DateTime.Parse(ownerTable.Rows[0]["Birth"].ToString());
                if (ownerTable.Rows[0]["Nationality"].ToString() != "")
                    FData.Own_Nationality = ownerTable.Rows[0]["Nationality"].ToString();
                if (ownerTable.Rows[0]["Male"].ToString() != "")
                    FData.Own_Gen = bool.Parse(ownerTable.Rows[0]["Male"].ToString());
                if (ownerTable.Rows[0]["Address"].ToString() != "")
                    FData.Own_Address = ownerTable.Rows[0]["Address"].ToString();
                if (ownerTable.Rows[0]["Email"].ToString() != "")
                    FData.Own_Email = ownerTable.Rows[0]["Email"].ToString();
                if (ownerTable.Rows[0]["Description"].ToString() != "")
                    FData.Description = ownerTable.Rows[0]["Description"].ToString();               
                return (FData);
            }
        }

        public static Ownerfield GetByOwnerName(string ownerName)
        {
            QASysDataSet.OWNERDataTable ownerTable = ownerAdapter.GetDataByOwnerName(ownerName);
            if (ownerTable.Rows.Count == 0)
                return null;
            else
            {
                Ownerfield FData = new Ownerfield();
                FData.Own_ID = int.Parse(ownerTable.Rows[0]["Own_Id"].ToString());
                FData.Own_Name = ownerTable.Rows[0]["Name"].ToString();
                if (ownerTable.Rows[0]["Birth"].ToString() != "")
                    FData.Own_Birth = DateTime.Parse(ownerTable.Rows[0]["Birth"].ToString());
                if (ownerTable.Rows[0]["Nationality"].ToString() != "")
                    FData.Own_Nationality = ownerTable.Rows[0]["Nationality"].ToString();
                if (ownerTable.Rows[0]["Male"].ToString() != "")
                    FData.Own_Gen = bool.Parse(ownerTable.Rows[0]["Male"].ToString());
                if (ownerTable.Rows[0]["Address"].ToString() != "")
                    FData.Own_Address = ownerTable.Rows[0]["Address"].ToString();
                if (ownerTable.Rows[0]["Email"].ToString() != "")
                    FData.Own_Email = ownerTable.Rows[0]["Email"].ToString();
                if (ownerTable.Rows[0]["Description"].ToString() != "")
                    FData.Description = ownerTable.Rows[0]["Description"].ToString();               
                return (FData);
            }
        }
    }
}